﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Marmat.Template.WinForm
{
    public partial class CreateRoleForm : Marmat.Forms.Form
    {
        internal Marmat.Foundation.IRoleEntity[] roleCollection;

        public CreateRoleForm()
        {
            InitializeComponent();
            var permissionManager = Marmat.FrameWork.SystemCommand.GetService<Marmat.Foundation.IPermissionManager>();
            this.comboBox1.DataSource = permissionManager.GetRoleCollection().Where(x => x.IsGroup);
        }

        private void comboBox1_CustomDisplayText(object sender, Forms.CustomDisplayTextEventArgs e)
        {
            if (e.Value is Marmat.Foundation.IRoleEntity role)
                e.DisplayText = role.Text;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (this.comboBox1.SelectedValue is not null && !string.IsNullOrEmpty(this.textBox1.Value))
            {
                this.DialogResult = DialogResult.OK;
            }
        }
    }
}
